package com.seaboxdata.util;

import com.seaboxdata.entity.DataMonitorConfig;
import com.seaboxdata.entity.DataMonitorResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.time.DateUtils;

/**
 * @author
 * @create 2021-11-08 14:35
 **/
@Slf4j
public class MonitorUtil {

    public static void setResult(DataMonitorResult result, DataMonitorConfig config,String invalidIntervalSecond) {
        if (result.getTotalCount() == null || result.getTotalCount() == 0) {
            result.setResult("异常");
        }

        switch (config.getPeriodUnit()) {
            case "S": {
                if (result.getLastCjsj() == null) {
                    result.setResult("异常");
                } else if (DateUtils.addMinutes(result.getLastCjsj(), Integer.valueOf(invalidIntervalSecond))
                        .compareTo(result.getMonitorDate()) == -1) {
                    result.setResult("异常");
                } else {
                    result.setResult("正常");
                }
                break;
            }
            default: {
                result.setResult("正常");
            }
        }
    }
}
